'use strict';

const conn = require('../../../libs/Conn');

module.exports = async function (updateParams) {
    let checkDepartmentSql = `SELECT department_name FROM department_file  WHERE department_name = ? AND department_id != ? AND delete_sign = 1`;
    let repeatData = (await conn(checkDepartmentSql, [updateParams.department_name,updateParams.department_id]));
    if (repeatData.shift()) {
        let repeat = `部门名称重复`;
        return {success: false, message: repeat};
    } /*else if(repeatData[1].shift()){
        let repeat = `部门编号重复`;
        return {success: false, message: repeat};
    }*/else {
        let updateObj = {
            department_name: updateParams.department_name,
            departmental_functions: updateParams.departmental_functions,
        };
        let updateSql = `UPDATE department_file ug SET ? WHERE department_id = ?`;
        await conn(updateSql, [updateObj, updateParams.department_id]);
        return {success: true};
    }
};